import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;


public class RandomSplit {

	public static void main(String[] args) {
        RandomSplit split = new RandomSplit();
        split.split();
    }
	
	public static void split(){

		
		File infile = new File("F:/tweets.csv");
		
		String directoryTrain = "F:/splitTrainTT/";
		String directoryTest = "F:/splitTestTT/";
		String fileNameTrain = "TrainingTweets";
		String fileNameTest = "TestingTweets";
		String extension = ".csv";
		
		int rotation = 1;
		
		File outFileTrain = new File(directoryTrain + fileNameTrain + extension);
		File outFileTest = new File(directoryTest + fileNameTest + extension);
		
		try{
			BufferedReader reader = new BufferedReader(new FileReader(infile));
			BufferedWriter writerTrain = new BufferedWriter(new FileWriter(outFileTrain));
			BufferedWriter writerTest = new BufferedWriter(new FileWriter(outFileTest));
			
			 String line = reader.readLine();
			 while(line != null){
				 
				 if(rotation<9){ //training set
					 writerTrain.write(line + "\n");
					 rotation++;
				 }
				 else if(rotation >= 9 && rotation < 11){ //testing set
					 writerTest.write(line + "\n");
					 rotation++;
				 }
				 else{
					 rotation = 1;
				 }
				 line = reader.readLine();
			 }
			 writerTrain.close();
			 writerTest.close();
			 reader.close();
			
		}catch(Exception e){e.printStackTrace();}
		
		
	}
    
	
	
}
